//#include <config.h>
//#include <encoding_manager.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include <config.h>
#include <font_manager.h>
#include <disp_manager.h>
#include <encoding_manager.h>
#include <input_manager.h>


static int isUtf16leCoding(unsigned char *pucBufHead);
static int Utf16leGetCodeFrmBuf(unsigned char *pucBufStart);

static T_EncodingOpr g_tUtf16leEncodingOpr = {
	.name          		= "utf-16le",
	.ucpFileMem		= NULL,
	.iBpc				= 2,
	.isSupport     		= isUtf16leCoding,
	.GetCodeFrmBuf 	= Utf16leGetCodeFrmBuf,
};

static int isUtf16leCoding(unsigned char *pucBufHead)
{
	const char aStrUtf16le[] = {0xFF, 0xFE};
	if (strncmp((const char *)pucBufHead, aStrUtf16le, 2) == 0)
	{
		/* UTF-16 little endian */
		g_tUtf16leEncodingOpr.ucpFileMem = pucBufHead + 2;
		DBG_PRINTF("This file is Unicode little endian!\n");
		return 0;
	}
	else
	{
		return 1;
	}
}

static int Utf16leGetCodeFrmBuf(unsigned char *pucBufStart)
{
	int First;
	int Second;
	int Code;
	First = *pucBufStart++;
	Second = *pucBufStart;
	Code = First | (Second<< 8) ;
	return Code;
}

int  Utf16leEncodingInit(void)
{
	//g_tUtf16leEncodingOpr.aptFontOprSupported[0] = GetFontOpr("freetype");
	//g_tUtf16leEncodingOpr.aptFontOprSupported[1] = NULL;	
	return RegisterEncodingOpr(&g_tUtf16leEncodingOpr);
}


